package com.geovis.emergency.spd.biz.basic.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.common.mybatis.page.PageParam;
import com.geovis.common.mybatis.page.PageResult;
import com.geovis.emergency.spd.biz.basic.mapper.BasicThirdPartyInterfaceMapper;
import com.geovis.emergency.spd.biz.basic.service.IBasicThirdPartyInterfaceService;
import com.geovis.emergency.spd.entity.basic.entity.BasicThirdPartyInterface;
import com.geovis.emergency.spd.entity.basic.pojo.dto.BasicThirdPartyInterfaceQueryDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 基础模块-集成接口 服务实现类
 * </p>
 *
 * @author 王响
 * @since 2022-03-13
*/

@Service
@RequiredArgsConstructor
@Slf4j
public class BasicThirdPartyInterfaceServiceImpl extends ServiceImpl<BasicThirdPartyInterfaceMapper, BasicThirdPartyInterface> implements IBasicThirdPartyInterfaceService {


    @Override
    public PageResult<BasicThirdPartyInterface> listPage(PageParam<BasicThirdPartyInterfaceQueryDTO> pageParam) {
        BasicThirdPartyInterfaceQueryDTO queryDTO = pageParam.getQuery();
        IPage<BasicThirdPartyInterface> page = pageParam.buildPage();
        page(page,buildWrapper(queryDTO));
        return new PageResult<BasicThirdPartyInterface>(page);
    }


    /**
     * 构建 wrapper
     *
     * @param queryDTO
     * @return
     */
    private LambdaQueryWrapper<BasicThirdPartyInterface> buildWrapper(BasicThirdPartyInterfaceQueryDTO queryDTO) {
        LambdaQueryWrapper<BasicThirdPartyInterface> wrapper = Wrappers.lambdaQuery(BasicThirdPartyInterface.class);
        if (ObjectUtil.isNull(queryDTO)) {
            return wrapper;
        }
        wrapper.like(ObjectUtil.isNotEmpty(queryDTO.getName()), BasicThirdPartyInterface::getName, queryDTO.getName())
                .like(ObjectUtil.isNotEmpty(queryDTO.getUrl()), BasicThirdPartyInterface::getUrl, queryDTO.getUrl())
                .eq(ObjectUtil.isNotEmpty(queryDTO.getDataStatus()), BasicThirdPartyInterface::getDataStatus, queryDTO.getDataStatus());
        return wrapper;
    }
}
